package com.cl.datasubscription.schedule;

import com.cl.chlorine.schedule.BaseStarter;
import com.cl.datasubscription.entity.SubscribeKeywordTask;
import com.cl.datasubscription.repository.SubscribeKeywordRepository;
import com.cl.datasubscription.task.SubscribeKeywordTaskExecutor;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;

import java.util.List;

@Component
public class SubscribeKeywordStarter extends BaseStarter<SubscribeKeywordTask> {

    @Autowired
    SubscribeKeywordRepository subscribeKeywordRepository;
    @Autowired
    SubscribeKeywordTaskExecutor subscribeKeywordTaskExecutor;

    public void startAll() {
        List<SubscribeKeywordTask> scheduleEntities = subscribeKeywordRepository.findAll();
        for (SubscribeKeywordTask schedule : scheduleEntities) {
            if (schedule.getIsOpen() == 1) {
                start(schedule);
            }
        }
    }
    @Override
    public void start(SubscribeKeywordTask entity) {
        subscribeKeywordTaskExecutor.consumer(entity);
    }
}
